package com.wf.mapper;

import com.wf.domain.Orders;
import com.wf.domain.User;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author mpk16
 * @description 针对表【orders】的数据库操作Mapper
 * @createDate 2024-08-20 21:40:02
 * @Entity com.wf.domain.Orders
 */
public interface OrdersMapper {


    // 1.根据订单号查询 用户姓名
// 根据订单号查询 用户姓名
    @Select("SELECT u.name AS userName FROM orders o JOIN user u ON o.user_id = u.id WHERE o.id = #{id}")
    String getUserNameByOrderId(Long id);

//    根据用户id查询 所属用户的订单有哪些?
    @Select("SELECT o.* FROM orders o JOIN user u ON o.user_id = u.id WHERE u.id = #{userId}")
    List<Orders> getOrdersByUserId(Long userId);


    int deleteByPrimaryKey(Long id);

    int insert(Orders record);

    int insertSelective(Orders record);

    Orders selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Orders record);

    int updateByPrimaryKey(Orders record);

}
